package com.zy.openchat.core.model.message;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.zy.openchat.util.Common;

import java.util.ArrayList;
import java.util.List;

public class ReplyMarkupInfo implements Parcelable {

    @SerializedName(value = "@type")
    public String type;

    public List<List<InlineKeyboardButton>> rows;

    public ReplyMarkupInfo(String type, List<List<InlineKeyboardButton>> rows) {
        this.type = type;
        this.rows = rows;
    }

    public List<InlineKeyboardButton>  temp;

    public List<InlineKeyboardButton> getTemp(){
        if(temp!=null){
            return temp;
        }
        temp = new ArrayList<>();
        if(!Common.isEmpty(rows)){
            for(List<InlineKeyboardButton> buttons:rows){
                if(!Common.isEmpty(buttons)){
                    temp.addAll(buttons);
                }
            }
        }
        return temp;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.type);
        dest.writeList(this.rows);
    }

    public void readFromParcel(Parcel source) {
        this.type = source.readString();
        this.rows = new ArrayList<List<InlineKeyboardButton>>();
        source.readList(this.rows, getClass().getClassLoader());
    }

    protected ReplyMarkupInfo(Parcel in) {
        this.type = in.readString();
        this.rows = new ArrayList<List<InlineKeyboardButton>>();
        in.readList(this.rows, getClass().getClassLoader());
    }

    public static final Creator<ReplyMarkupInfo> CREATOR = new Creator<ReplyMarkupInfo>() {
        @Override
        public ReplyMarkupInfo createFromParcel(Parcel source) {
            return new ReplyMarkupInfo(source);
        }

        @Override
        public ReplyMarkupInfo[] newArray(int size) {
            return new ReplyMarkupInfo[size];
        }
    };
}
